<template>
	<view class="">
		<view class="my" v-if='!isshow'>
			<view class="user">
				<image v-if="initData.image" :src="initData.image" class="portrayal" @click="go_url('/pages/shop/my/information')" />
				<image v-else src="/static/img/logo2.png" class="portrayal" @click="go_url('/pages/shop/my/information')" />
				<view class="text">
					<view class="name">{{ initData.member.nickName }}</view>
					<view class="LV" v-if="initData.member.memberRank">{{ initData.member.memberRank.desp }} {{initData.member.memberNo}}</view>
				</view>
				<view class="agency" v-if="initData.member.isAgent.value == 0" @click="applay"><text>申请代理</text></view>
				<!-- <view class="agency" v-else @click="go_url('../agent/index')"><text>代理中心</text></view> -->
				<view class="news" @click="go_url('/pages/shop/news/msglist')">
					<image src="/static/img/information_1.png" />
					<text v-if="news_l">{{ news_l }}</text>
				</view>
				<image src="/static/img/my_bg.png" class="bg" />
			</view>
			<view class="information">
				<view @click="go_url('/pages/shop/integral/myjifen')">
					<view class="number">{{ initData.myPoints }}</view>
					<view class="text">我的积分</view>
				</view>
				<view @click="go_url('/pages/shop/my/collect')">
					<view class="number">{{ initData.myStore }}</view>
					<view class="text">我的收藏</view>
				</view>
				<view @click="go_url('/pages/shop/my/footprint')">
					<view class="number">{{ footprint }}</view>
					<view class="text">我的足迹</view>
				</view>
			</view>
			<view class="order">
				<view class="title">
					我的订单
					<text class="right" @click="go_order(0)">查看全部订单 >></text>
				</view>
				<view class="list">
					<view class="list_list" @click="go_order(1)">
						<image src="/static/img/order_1.png" />
						<view class="text">待付款</view>
						<text class="tip" v-if="initData.waitPay">{{ initData.waitPay }}</text>
					</view>
					<view class="list_list" @click="go_order(3)">
						<image src="/static/img/order_2.png" />
						<view class="text">待发货</view>
						<text class="tip" v-if="initData.waitSend">{{ initData.waitSend }}</text>
					</view>
					<view class="list_list" @click="go_order(4)">
						<image src="/static/img/order_3.png" />
						<view class="text">待收货</view>
						<text class="tip" v-if="initData.waitRecieve">{{ initData.waitRecieve }}</text>
					</view>
					<view class="list_list" @click="go_order(5)">
						<image src="/static/img/order_4.png" />
						<view class="text">已完成</view>
						<text class="tip" v-if="initData.finish">{{ initData.finish }}</text>
					</view>
					<view class="list_list" @click="go_order(6)">
						<image src="/static/img/order_5.png" />
						<view class="text">退款/退货</view>
						<text class="tip" v-if="initData.afterSale">{{ initData.afterSale }}</text>
					</view>
				</view>
			</view>
			<view class="panel">
				<view class="panel_list" @click="go_url('/pages/shop/my/affiliation')" v-if="initData.member.isAgent.value == 0">
					<image src="/static/img/panel_1.png" />
					<view class="text">所属代理</view>
				</view>
				<view class="panel_list" @click="checkagent" v-else>
					<image src="/static/img/panel_1.png" />
					<view class="text">代理中心</view>
				</view>
				<!-- <view class="panel_list" @click="tip">
					<image src="/static/img/panel_2.png" />
					<view class="text">会员等级</view>
				</view> -->
				<view class="panel_list" @click="gointegral">
					<image src="/static/img/panel_3.png" />
					<view class="text">积分兑换</view>
				</view>
				<view class="panel_list" @click="go_url('/pages/shop/my/address')">
					<image src="/static/img/panel_4.png" />
					<view class="text">地址管理</view>
				</view>
				<view class="panel_list">
					<image src="/static/img/panel_5.png" @click="go_url('/pages/shop/my/store')" />
					<view class="text">附近店铺</view>
				</view>
				<view class="panel_list" @click="go_url('/pages/shop/my/contact')">
					<image src="/static/img/panel_6.png" />
					<view class="text">联系我们</view>
				</view>
				<view class="panel_list" @click="go_url('/pages/shop/my/feedback')">
					<image src="/static/img/panel_7.png" />
					<view class="text">意见反馈</view>
				</view>
				<view class="panel_list" @click="go_url('/pages/shop/my/help')">
					<image src="/static/img/panel_8.png" />
					<view class="text">帮助中心</view>
				</view>
				<view class="panel_list" @click="go_url('/pages/shop/my/set')">
					<image src="/static/img/panel_9.png" />
					<view class="text">设 置</view>
				</view>
			</view>
		</view>
		<view class="login" v-if="isshow" @click="go_url('./account/login')">
			请先登录
		</view>
	</view>
	
</template>

<script>
	import my from '../../servers/shop/my.js';
	export default {
		props: ['paging'],
		data() {
			return {
				news_l: 0,
				initData: {
					member:{
						nickName:'',
						isAgent:{
							value:0
						}
					}
				},
				login: '',
				footprint: 0,
				isshow:false
			};
		},
		onShow() {
			this.login = uni.getStorageSync('login');
			console.log(this.login)
			if (this.login) {
				this.getDate();
				var footprint = uni.getStorageSync('footprint')
				this.footprint = footprint.length
				this.initData.member=this.login
			} else {
				uni.navigateTo({
					url: '/pages/shop/account/login'
				});
			}
		},
		onPullDownRefresh() {
			var _this=this;
		      uni.startPullDownRefresh({
		      	success() {
					_this.getDate();
					setTimeout(function () {
						
					    uni.stopPullDownRefresh();
					}, 1000);
		      		
		      	}
		      })
		       
		    },
		methods: {
			tip() {
				uni.showToast({
					title: '功能暂未开放，请期待···',
					icon: 'none'
				})
			},
			gointegral(){
				uni.navigateTo({
					url:'/pages/shop/integral/index?integral='+this.initData.myPoints
				})
			},
			applay(){
				my.checkAgentApply()
					.then(res => {					
						if(res.code==200){
							if(res.data==0){
								uni.navigateTo({
									url:'../agent/proposer?phone='+this.initData.member.mobile
								})
							}else{
								uni.showToast({
									title:'您已提交申请，请勿重复提交',
									icon:'none'
								})
							}
							
						}
						
					})
					.catch(err => {
						console.log(err)
						console.log(new Error('请检查网络后重试'));
					});
				
				
			},
			checkagent(){
				console.log(uni.getStorageSync('agentinfo'))
				if(uni.getStorageSync('agentinfo')){
					uni.navigateTo({
						url:'/pages/agent/index?obj='+uni.getStorageSync('agentinfo')
					})
				}else{
					uni.showToast({
						title:'代理商服务不可用，请联系管理员',
						icon:'none'
					})
				}
				
			},
			getDate() {
				var _this = this;
				uni.showLoading({
					title: '加载中',
					mask: true
				});
				my.initData()
					.then(res => {
						console.log(res)
						if(res.code==200){
							this.isshow=false
							this.initData = res.data;
							if (this.initData.member.avator) {
								this.initData.image = this.imgCDNUrl + this.initData.member.avator;
							}
							console.log(res, _this.initData);
							// uni.hideLoading();
						}else{
							this.isshow=true
						}
						uni.hideLoading();
					})
					.catch(err => {
						console.log(err)
						console.log(new Error('请检查网络后重试'));
					});
				my.noReadMessage()
					.then(res => {
						_this.news_l = res.data;
					})
					.catch(err => {
						console.log(new Error('请检查网络后重试'));
					});
			},

			go_url(url) {
				uni.navigateTo({
					url: url
				});
			},
			go_order(parame) {
				console.log(parame);
				if (parame == 6) {
					//跳轉至我的退货页面
					// this.commonality.route_baling('/pages/shop/order/afterlist','shoporderafterlist',parame)
					uni.setStorage({
						key: 'shoporderafterlist',
						data: parame,
						success: function() {
							uni.navigateTo({
								url: '/pages/shop/order/afterlist'
							});
						}
					});
				} else {
					//跳转到我的订单页面
					uni.navigateTo({
						url:'/pages/shop/order/list?shoporderlist='+parame
					})
					// this.commonality.route_baling('/pages/shop/order/list', 'shoporderlist', parame)
				}
			},
			//跳转至我的收藏页面
			go_collect(parame) {
				url: 'pages/shop/my/collect';
			},
			//我的足迹
			go_footprint(parame) {
				url: 'pages/shop/my/footprint';
			}
		}
	};
</script>

<style lang="less" scoped>
	.my {
		height: 100%;
		overflow: auto;
		-webkit-overflow-scrolling: touch;
		background: #f7f7f7;

		.user {
			position: relative;
			color: #fff;
			padding: 112rpx 20rpx 46rpx;
			display: flex;
			overflow: hidden;
			z-index: 9;

			.portrayal {
				width: 140rpx;
				height: 140rpx;
				border-radius: 50%;
			}

			.text {
				padding: 32rpx 25rpx;
				font-size: 30rpx;

				.LV {
					margin-top: 25rpx;
					font-size: 24rpx;
				}
			}

			.agency {
				position: absolute;
				right: -5rpx;
				top: 50%;
				border: 5rpx solid rgba(255, 194, 31, 0.3);
				border-top-left-radius: 68rpx;
				border-bottom-left-radius: 68rpx;
				width: 182rpx;
				text-align: center;
				line-height: 68rpx;
				font-size: 30rpx;
				overflow: hidden;

				text {
					display: block;
					background: #ffc21f;
				}
			}

			.news {
				position: absolute;
				right: 0;
				top: 70rpx;

				image {
					width: 43rpx;
					height: 43rpx;
					padding: 7rpx 20rpx;
				}

				text {
					position: absolute;
					top: -3rpx;
					right: 6rpx;
					width: 30rpx;
					height: 30rpx;
					border-radius: 50%;
					text-align: center;
					line-height: 30rpx;
					background: #fff;
					font-size: 24rpx;
					color: #ff2100;
				}
			}

			.bg {
				position: absolute;
				width: 100%;
				height: 100%;
				top: 0;
				left: 0;
				z-index: -1;
			}
		}

		.information {
			display: flex;
			background: #fff;
			text-align: center;
			font-size: 28rpx;
			padding: 36rpx 0 29rpx;
			margin-bottom: 26rpx;

			view {
				flex: 1;

				.number {
					font-size: 34rpx;
					margin-bottom: 27rpx;
				}
			}
		}

		.order {
			background: #fff;
			padding: 37rpx 20rpx 52rpx;
			margin-bottom: 26rpx;

			.title {
				font-size: 30rpx;

				.right {
					font-size: 26rpx;
					color: #999;
				}
			}

			.list {
				display: flex;
				width: 100%;

				.list_list {
					flex: 1;
					width: 20%;
					text-align: center;
					position: relative;
					padding-top: 60rpx;
					font-size: 26rpx;

					image {
						width: 57rpx;
						height: 48rpx;
						margin-bottom: 16rpx;
					}

					.tip {
						position: absolute;
						top: 46rpx;
						left: 50%;
						width: 30rpx;
						height: 30rpx;
						border-radius: 50%;
						text-align: center;
						line-height: 30rpx;
						background: #fff;
						border: 2rpx solid #bd3c8c;
						font-size: 28rpx;
						color: #bd3c8c;
						margin-left: 5rpx;
					}
				}
			}
		}

		.panel {
			overflow: hidden;
			background: #fff;
			margin-bottom: 26rpx;
			display: flex;
			flex-wrap: wrap;
			.panel_list {
				flex: 0 0 33.3%;
				font-size: 28rpx;
				text-align: center;
				box-sizing: border-box;
				border-bottom: 1rpx solid #e1e1e1;
				/*no*/
				border-right: 1rpx solid #e1e1e1;
				/*no*/
				padding: 66rpx 0 53rpx;

				image {
					width: 63rpx;
					height: 63rpx;
					margin-bottom: 25rpx;
				}
				
			}

			view:nth-child(3n) {
				border-right: none;
			}

			
		}
	}

	.login {
		margin: 500rpx 40rpx 0;
		line-height: 90rpx;
		background: linear-gradient(80deg, #d2158a, #fc6395);
		text-align: center;
		color: #fff;
		border-radius: 45rpx;
		font-size: 32rpx;
		box-shadow: 3rpx 0 20rpx rgba(206, 205, 204, 0.35);
	}
</style>
